﻿using System;
using System.Collections.Generic;
#if !NETFX_CORE
using System.Data.Entity;
#endif
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Implements;
using Cofe.Core.Service;
using Cofe.Data;
using Cofe.Core.Interfaces;

namespace Cofe.Core
{
    #if !NETFX_CORE
    public class ManualBootStrapperIODB : ManualBootStrapperIO
    {
        private bool _newDatabase;
        private CacheUpdateOptions _updateOptions;

        public ManualBootStrapperIODB(bool allowReregister = false, bool newDatabase = false,
            CacheUpdateOptions updateOptions = CacheUpdateOptions.Passive, params ICofeService[] additionalServices)
            : base(allowReregister, additionalServices)
        {
            _newDatabase = newDatabase;
            _updateOptions = updateOptions;
            
        }

        protected override void ConfigureServiceImporter(ManualServiceImporter msi)
        {
            msi.RegisterCOFECore();
            msi.RegisterCOFEIO(true);
            msi.RegisterCOFEDB();
            Database.SetInitializer(new CofeDbContext.Initializer(_newDatabase));            
        }

        public override void Run(params ICofeService[] additionalServices)
        {
            if (!_allowReregister)
                if (CofeServices.ServiceImported)
                    return;
            base.Run(additionalServices);
            CofeServices.CofeSettings.CacheUpdateOptions = _updateOptions;
            if (_updateOptions == CacheUpdateOptions.Active)
                CofeDBServices.ActiveDatabaseUpdater.StartActiveUpdate();
        }

    }
    #endif

  
}
